#pragma once
#include <vector>

namespace hiveDVR
{
	struct STransferFunctionPoint
	{
		int Scalar;
		glm::vec4 Color;
		STransferFunctionPoint(int vScalar, const glm::vec4& vColor = glm::vec4(0.0f))
			: Scalar(vScalar), Color(vColor)
		{
		}

		bool operator<(const STransferFunctionPoint& vPoint) const { return Scalar < vPoint.Scalar; }
	};

	class CTransferFunction
	{
	public:
		CTransferFunction() = default;
		~CTransferFunction() = default;

		void init(size_t vExtent);
		void update(int vMinIntensity, int vMaxIntensity, int vMinGradient, int vMaxGradient);
		void addPoint(int vValue, float vOpacity);
		void addPoint(int vValue, const glm::vec4& vColor);

		void reset();
		size_t getExtent() const { return m_Extent; }
		glm::vec4* getPtrOfColorSet() { return m_ColorSet.data(); }

		bool isUsingGradient() const { return m_UseGradient; }

	private:
		std::vector<STransferFunctionPoint> m_PointSet;
		std::vector<glm::vec4> m_ColorSet;

		bool m_UseGradient = false;
		size_t m_Extent = 0;

		void __updatePalette(std::vector<STransferFunctionPoint>::iterator& vIterator);
		void __linearInterpolateBetween(const STransferFunctionPoint& vLeft, const STransferFunctionPoint& vRight);
	};
}